home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / 80X86 / ASMANDEL.ZIP / ASMANDEL.ASM next >
Encoding:
Assembly Source File  |  1995-11-10  |  8.4 KB  |  278 lines

  1. ;*****************************************************************************
  2. ;*
  3. ;*  ASMANDEL by (c) Taslehof / Null Pointer Assignment 1995   v1.0
  4. ;*
  5. ;*   This code is freeware. Only one thing: if you use it please remember me.
  6. ;*   ASMANDEL is the Mandelbrot's fractal in assembler, I use the iterated
  7. ;*   mode,the default number is 150 iterations
  8. ;*   The metod I used: we have the left upper corner point, and the size of
  9. ;*   the side. This is the zone will be zoom up to the screen's resolution.
  10. ;*   That's all folks!  See you soon.
  11. ;*   WARNING: YOU MUST HAVE A COPRO (8087+), or at least, a emulator.
  12. ;*
  13. ;*
  14. ;*****************************************************************************
  15.  
  16. .MODEL SMALL
  17. .STACK 200h
  18. .DATA
  19. ;=============================================================================
  20. ;=                            DATOS DEL PROGRAMA                             =
  21. ;=============================================================================
  22.  
  23. ;Datos    LABEL    BYTE
  24.  
  25.      MandelX  DD   -2.50           ;left y point of mandel
  26.      Mandely  DD   -1.50           ;left x point of mandel
  27.      Resx     =     320            ;resolution X
  28.      Resy     =     200            ;resolution y
  29.      Lado     DW    5              ;size of
  30.      Iteration DW   200            ;number of iterations
  31.      A        DD    0.0            ;general var
  32.      B        DD    0.0
  33.      X        DD    0.0
  34.      Y        DD    0.0
  35.      Xaux     DD    0.0
  36.      Yaux     DD    0.0
  37.      VGA      =     0A000h         ;my VGA and you
  38.      ESCALA   DD    0.015625       ;scale= lado /resx
  39.      KK       DD    ?              ;kk???
  40.      Color    DB    ?
  41.      Estado   DW    ?
  42.      DOS      DD    2
  43.      Caracter DB    0,0,0,0,0,255,255,255,255,255,255,0,0,0,0,0
  44.      TEXTO    DB    ' (c) TASLEHOF / Null Pointer Assignment 1995',10,13
  45.           DB    '        Saludos a la gente de la U.G.R Informatica',10,13
  46.           DB    '        If you have some request or some comment my email address:',10,13
  47.           DB    '                       jagarcia@verne.ugr.es                    ',10,13
  48.           DB    '$'
  49.      INCLUDE  FIRE.INC
  50. ;-----------------------------------------------------------------------------
  51. ;----------------------------[ FIN DE LOS DATOS ]-----------------------------
  52. ;-----------------------------------------------------------------------------
  53. ;
  54.  
  55. .CODE
  56. ;=============================================================================
  57. ;=                    CUERPO PRINCIPAL DEL PROGRAMA                          =
  58. ;=============================================================================
  59.  
  60. Main:
  61.      MOV     AX,@DATA              ;my data segment
  62.      MOV     DS,AX
  63.      MOV     AX,VGA                ;es = vga
  64.      MOV     ES,AX                 ;lets go to 13h
  65.      MOV     AX,13h
  66.      INT     10h
  67.      CALL    PAL
  68.  
  69.      MOV     CX,319                ;For x=0 to 320 do begin
  70. Loopx:   MOV     SI,CX                 ;si=cx to acces it easier.
  71.      MOV     WORD PTR KK,CX
  72.      MOV     WORD PTR KK+2,0
  73.      FINIT                         ;
  74.      FILD    KK                    ;A=x*escala+mandelx, this is necesari for calculate
  75.      FMUL    Escala                ;the color of point (si,di)
  76.      FADD    Mandelx               ;
  77.      FSTP    A                     ;is necesari for whatcolor
  78.                        ;the parameters is pases by memori
  79.  
  80.      PUSH    CX                    ;
  81.                        ;loop whith the y
  82.      MOV     CX,199
  83. Loopy:   MOV     DI,CX                 ;
  84.      MOV     WORD PTR KK,CX        ;B=y*escala+mandely
  85.      MOV     WORD PTR KK+2,0
  86.      FINIT
  87.      FILD    KK
  88.      FMUL    Escala
  89.      FADD    MandelY
  90.      FSTP    B                     ;
  91.  
  92.  
  93.      CALL    WHATCOLOR             ;this calculate the color whith A ,B
  94.      WAIT
  95.  
  96.      MOV     AX,DI                 ;Draw the color  the pos (si,di):=color
  97.      MOV     BX,AX
  98.      SHL     AX,8
  99.      SHL     BX,6
  100.      ADD     BX,AX
  101.      ADD     BX,SI
  102.      MOV     Al,BYTE PTR Color
  103.      MOV     ES:[BX],Al            ;
  104.  
  105.      LOOP    Loopy
  106.      POP     CX
  107.      LOOP    Loopx                 ;end of a line
  108.  
  109.  ReadK:  MOV     AH,1
  110.      INT     16h
  111.      JZ      ReadK
  112.      MOV     AX,03h                ;go to test mode
  113.      INT     10h
  114.      CALL    THEEND
  115.      MOV     AX,4C00h
  116.      INT     21h
  117. ;------------------------[ FIN DEL CUERPO DEL PROGRAMA ]----------------------
  118.  
  119.  
  120. ;.............................................................................
  121. ;::                     PROCEDIMIENTO DE CALCULO DEL COLOR                  ::
  122. ;.............................................................................
  123.  
  124.  
  125. WHATCOLOR        PROC
  126.           PUSH    CX           ;keep register in use
  127.           PUSH    DI
  128.           PUSH    SI
  129.           FINIT
  130.           FLD     X            ;PUSH ,ST=X
  131.           FSUB    X            ;ST=X-X
  132.           FSTP    X            ;X=X-X=0 , POP
  133.           FLD     Y            ;PUSH , ST=Y
  134.           FSUB    Y            ;ST = ST-Y
  135.           FSTP    Y            ;Y=ST=0  , POP
  136.           MOV     CX,iteration ;iterations
  137.  
  138.                        ;keep the registers
  139.       @bucle: PUSH    ES
  140.           PUSH    CX
  141.           MOV     AX,DS        ;ES=DS
  142.           MOV     ES,AX
  143.                        ;lets to copy xaux=x
  144.           MOV     CX,4
  145.           MOV     SI,OFFSET X
  146.           MOV     DI,OFFSET Xaux
  147.           REP     MOVSB
  148.                        ;same yaux=y
  149.           MOV     CX,4
  150.           MOV     SI,OFFSET Y
  151.           MOV     DI,OFFSET Yaux
  152.           REP     MOVSB
  153.  
  154.           POP     CX           ;well
  155.           POP     ES           ;
  156.  
  157.  
  158.           FINIT
  159.           FLD     Xaux         ;st = xaux
  160.           FMUL    Xaux         ;st = st* Xaux
  161.           FLD     Yaux         ;push st ,st(1)=xaux^2 , st=yaux
  162.           FMUL    Yaux         ;st = yaux^2
  163.           FSUBR   ST,ST(1)     ;st = st-st(1) +- st =xaux^2-yaux^2
  164.           FADD    A            ;st = st+ a
  165.           FSTP    X            ;X  = xaux^2 + yaux^2 + a ,pop
  166.           FFREE   ST(0)        ;set st=0
  167.  
  168.           FLD     Xaux         ;st = xaux
  169.           FMUL    Yaux         ;st = xaux * yaux
  170.           FIMUL   DOS          ;st = xaux * yaux *2
  171.           FADD    B            ;st = xaux * yaux *2 +b
  172.           FSTP    Y            ;y  = st
  173.  
  174.           FLD     X            ;st = x
  175.           FMUL    X            ;st = st* x
  176.           FSTP    KK           ;KK = x^2
  177.           FLD     Y            ;st = y ,st(1)= x^2
  178.           FMUL    Y            ;st = st * y = y^2
  179.           FADD    kk           ;st = x^2+y^2
  180.           FSQRT                ;st = st^1/2
  181.  
  182.  
  183.           FICOM   DOS          ;st = st-2
  184.           FSTSW   ESTADO       ;estado = word of state of the copro
  185.           FWAIT                ; no comment
  186.           MOV     AH,BYTE PTR ESTADO+1
  187.           SAHF                 ;set flag
  188.  
  189.           JA      @FIN         ;
  190.  
  191.           DEC     CX
  192.           CMP     CX,0
  193.           JE      @FIN         ;this jump is so far
  194.           JMP     @BUCLE       ;lets use JMP
  195.         @FIN:
  196.           CMP     CX,0         ;and calc the color with the number of iterations
  197.           JNE     NOFINITO
  198.           MOV     BYTE PTR COLOR,254
  199.           JMP     EXIT
  200.     NOFINITO:
  201.           ;MOV     AX,CX
  202.           ;MOV     CX,2
  203.           ;MUL     CX
  204.           ;MOV     CX,AX
  205.           ADD     CX,40
  206.           MOV     BYTE PTR COLOR,CL    ;!!!!! CH !!!!!!! ja
  207.  
  208.     EXIT:     POP     SI
  209.           POP     DI
  210.           POP     CX
  211.           RET
  212.  
  213.         ENDP
  214.  
  215. ;-----------------------------[FIN DE WHATCOLOR ]----------------------------
  216.  
  217. ;.............................................................................
  218. ;::             PROC PAL = SET A FIRE PALETTE                                ::
  219. ;.............................................................................
  220.  
  221. PAL       PROC
  222.        mov  cx,255
  223.        mov  bx,offset paleta
  224.       @@1: mov  dx,3C8h
  225.        mov  al,cl
  226.        out  dx,al
  227.        inc  dx
  228.        mov  al,[bx]
  229.        out  dx,al
  230.        mov  al,[bx+1]
  231.        out  dx,al
  232.        mov  al,[bx+2]
  233.        out  dx,al
  234.        add  bx,3
  235.        loop @@1
  236.        ret
  237.       endp
  238.  
  239.  
  240. ;.............................................................................
  241. ;::                     PROC THEEND WRITE THE CREDITS AND THE FLAG            ::
  242. ;.............................................................................
  243.  
  244. THEEND     PROC
  245.         MOV     AX,@DATA
  246.         MOV     ES,AX
  247.         MOV     BP,OFFSET (caracter)    ;lets change the 219 for my flag char
  248.         MOV     AX,1100h
  249.         MOV     BH,16
  250.         MOV     BL,0
  251.         MOV     CX,1
  252.         MOV     DX,219
  253.         INT     10h
  254.         MOV     AH,09h                  ;Write 3 char #219
  255.         MOV     AL,219
  256.         MOV     BH,0
  257.         MOV     BL,78
  258.         MOV     CX,3
  259.         INT     10h
  260.                         ;¿what is the cursor position?
  261.         MOV     AH,03h
  262.         MOV     BX,0                    ;RETURN DH=column ,DL=row
  263.         INT     10h
  264.  
  265.         ADD     DL,3                    ;
  266.         MOV     AH,02h
  267.         MOV     BH,0                    ; set the cursor in 3 pos right
  268.         INT     10h
  269.  
  270.         MOV     DX,OFFSET Texto         ; set credits
  271.         MOV     AH,9
  272.         INT     21h
  273.         RET
  274.        ENDP
  275.  
  276.      END     Main
  277.  
  278.